
const core = require('@babel/core');
/**
 * 根据老代码，生成新代码
 * @param {*} source 
 * @returns 
 */
 const { getOptions, interpolateName } = require("loader-utils");
function loader(source,inputSourceMap,data){
  let options = getOptions(this)||{};
  options.sourceMaps=true;//肯定要生成sourceMap
  options.inputSourceMap = inputSourceMap;//把前一个loader传过的sourcemap接着往下传
  //this.request = loader3!c:/src/index.js
  console.log('this.request',this.request);
  options.filename = this.request.split('!').pop().split('/').pop();
  let {code,map,ast} = core.transform(source,options);
  //如果你想给下一个loader返回多个值的话就可以使用callback
  //return只能返回一个值
  this.callback(null,code,map,ast);
  //假如说下一个loader也需要用到ast语法树的话
}

module.exports = loader;

//1
//loader1 +1=2
//loader2 +1=3
//loader3 +1=4

